package com.atguigu.system.service.impl;

import com.atguigu.model.system.SysUserRole;
import com.atguigu.system.mapper.SysUserRoleMapper;
import com.atguigu.system.service.SysUserRoleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户角色 服务实现类
 * </p>
 *
 * @author lemon
 * @since 2023-01-23
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements SysUserRoleService {

    /**
     * 根据用户id查询
     * @param userId
     * @return
     */
    @Override
    public List<String> getRoleIdsByUserId(Long userId) {
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SysUserRole::getUserId, userId);
        List<SysUserRole> list = list(lambdaQueryWrapper);
        if(list != null && list.size() > 0) {
            List<String> collect = list.stream().map(item -> {
                return item.getRoleId();
            }).collect(Collectors.toList());

            return collect;
        }
        return null;
    }
}
